package com.gko100.dao.impl;

import java.util.List;

import com.gko100.dao.CategoryDao;
import com.gko100.dao.basehibernatesupport.BaseHibernateDaoSupport;
import com.gko100.model.Category;


public class CategoryDaoHibernate extends BaseHibernateDaoSupport implements CategoryDao {

	public void delete(Category cate) {
		
		this.getHibernateTemplate().delete(cate);
		
	}

	public Category findCateByCateId(Integer cateId) {
		
		Category cate = this.getHibernateTemplate().get(Category.class, cateId);
		if(cate!=null){
			return cate;
		}else{
			logger.debug("method='findCateByCateId',cate 为空");
			return null;
		}
	}

	public List<Category> findCateListByCatePid(Integer catePid) {
		
		List<Category> cateList = this.getHibernateTemplate().find("from Category as c where c.catePid=?",catePid);
		
		if(cateList!=null&&cateList.size()>=1){
			
			return cateList;
		}else{
		
			return null;
		}
	}

	public List<Category> findCateAll() {
		
		List<Category> cateList = this.getHibernateTemplate().find("from Category");
		if(cateList!=null&&cateList.size()>=1){
			return cateList;
		}else{
			
			return null;
		}
	}

	public void save(Category cate) {
		
		this.getHibernateTemplate().save(cate);
		
	}

	public void update(Category cate) {
		
		this.getHibernateTemplate().update(cate);
		
	}

	public Category findCateByCateNote(String cateNote){
		
		List<Category> cateList = this.getHibernateTemplate().find("from Category as c where c.cateNote=?",cateNote);
		if(cateList!=null&&cateList.size()>=1){
			return cateList.get(0);
		}else{
			
			return null;
		}
		
		
	}
	

}
